﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using UnityDemo.Service;

namespace UnityDemo
{
    public class ContainerConfig
    {

        /// <summary>
        /// 配置文件注入
        /// </summary>
        public static void ContainerConfiguration()
        {

          
            IUnityContainer container = new UnityContainer();
            container.LoadConfiguration("MyContainer");
            UnityConfigurationSection section
              = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");//获取指定名称的配置节   
            section.Configure(container, "MyContainer");//获取特定配置节下已命名的配置节<container name='MyContainer'>下的配置信息

            IProductService classInfo = container.Resolve<IProductService>("SugarService");
            classInfo.ClassName = classInfo.GetType().ToString();
            classInfo.ShowInfo();
        }

    }
}